<?php
session_start();
error_reporting(0);

class Facebook {
	
	function setSession($code){
		$response = file_get_contents("https://graph.facebook.com/oauth/access_token?client_id=224416074306696&redirect_uri=http://www.thehi.me/pennapps/auth.php&client_secret=aa381593c5dce50d356c5bd8b653c069&code=$code");
		
		$temp = explode("&", $response);
		$authKey = explode("=", $temp[0]);
		
		$_SESSION['authKey'] = $authKey[1];
	}
	
	function get_likes($id){
		if(empty($id)){
			$id = "me";	
		}
    	$likes = array();
		$apiLink = "https://graph.facebook.com/$id/likes?access_token=".$_SESSION['authKey'];

	    $json = json_decode(file_get_contents("$apiLink"));
    	$json_data = $json->{'data'};

  	  	foreach ($json_data as $a){
			array_push($likes, $a -> {"name"});
    	}

   		$_SESSION['likes'] = $likes;
	}
	
	function get_friends(){
		$apiLink = "https://graph.facebook.com/me/friends?access_token=".$_SESSION['authKey'];
	    $json = json_decode(file_get_contents("$apiLink"));
		$json = json_encode($json -> {"data"});
		return str_replace("name:", "text:", $json);
	}
}